<?php

namespace App\Http\Controllers\api\customer;

use App\Http\Controllers\Controller;
use App\Server\ApiService;
use App\Server\QiniuService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class CustomerController extends Controller
{
    /**
     * Name: 存储聊天记录
     * User: 王梓墨
     * Date: 2023/7/7
     * Time:15:29
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function mongo(Request $request)
    {
        $data = $request->all();
        $res = json_decode($data['tmp'],true);
//        dd($res);
        $set = $res['fromid'] . '-' . $res['toid'];
        DB::connection('mongodb')       //选择使用mongodb
        ->collection($set)           //选择使用用户对用户的集合
        ->insert($res);
        return ApiService::success('存储成功',$res);
    }

    /**
     * Name: 将发送的图片存储到七牛云桶
     * User: 王梓墨
     * Date: 2023/7/7
     * Time:15:41
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse|string
     */
    public function customerImg(Request $request)
    {
        $file=$request->file('img');

        $img=Storage::disk('public')->put('shixunhealthcare/customer', $file);
        $image=QiniuService::qiniu("storage/".$img);

        return $image;
    }

    public function mongoImg(Request $request)
    {
        $data = $request->all();
        $res = json_decode($data['tmp'],true);
//        dd($res);
        $set = $res['fromid'] . '-' . $res['toid'];
//        dd($res);
        DB::connection('mongodb')       //选择使用mongodb
        ->collection($set)           //选择使用用户对用户的集合
        ->insert($res);
        return ApiService::success('存储成功',$res);
    }
}
